package com.workoutgrabber.ui.panels;

import java.awt.CardLayout;
import java.util.Map;

import com.workoutgrabber.ui.listeners.ExerciseCreatedEvent;
import com.workoutgrabber.ui.listeners.ExerciseCreatedListener;

public class ExerciseChooser extends ExercisePanel implements ExerciseCreatedListener {
	private CardLayout layout;
	
	public ExerciseChooser(Map<ExerciseName, ExercisePanel> exercisePanels){
		super();

		layout = new CardLayout();
		this.setLayout(layout);

		for (ExerciseName name : exercisePanels.keySet()) {
			ExercisePanel panel = exercisePanels.get(name);
			
			add(panel, name.getName());
			panel.addExerciseCreateListener(this);

		}		
	}
	
	public void addPanel(ExerciseName name, ExercisePanel panel){
		add(panel, name.getName());
		panel.addExerciseCreateListener(this);
	}
	
	public void showPanel(ExerciseName name){
		layout.show(this, name.getName());
	}

	@Override
	public void exerciseCreated(ExerciseCreatedEvent event) {
		for (ExerciseCreatedListener listener : listeners)
			listener.exerciseCreated(event);
	}
}
